#include "LED.h"

GPIO_TypeDef* LED_PORT[LEDn] = {LED0_PORT,LED1_PORT};
const uint16_t LED_PIN[LEDn] = {LED0_PIN,LED1_PIN};
const uint32_t LED_CLK[LEDn] = {LED0_CLK,LED1_CLK};

void LedInitController()
{
  	GPIO_InitTypeDef  GPIO_InitStructure;

  /* Enable the GPIO_LED Clock */ 
	RCC_APB2PeriphClockCmd(LED0_CLK, ENABLE);
	RCC_APB2PeriphClockCmd(LED1_CLK, ENABLE);

	/* Configure the LED0_PIN */
	GPIO_InitStructure.GPIO_Pin = LED0_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(LED_PORT[LED0], &GPIO_InitStructure);

	/* Configure the LED1_PIN */
	GPIO_InitStructure.GPIO_Pin = LED1_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(LED_PORT[LED1], &GPIO_InitStructure);	
  LedOff(LED0);
	LedOff(LED1);
}

void LedOff(Led_TypeDef Led)
{
	LED_PORT[Led]->BSRR = LED_PIN[Led];     
}

/**
  * @brief  Turns selected LED Off.
  * @param  Led: Specifies the Led to be set off. 
  *   This parameter can be one of following parameters:
  *     @arg LED0
  *     @arg LED1
  * @retval None
  */
void LedOn(Led_TypeDef Led)
{
	LED_PORT[Led]->BRR = LED_PIN[Led];    
}

/**
  * @brief  Toggles the selected LED.
  * @param  Led: Specifies the Led to be toggled. 
  *   This parameter can be one of following parameters:
  *     @arg LED0
  *     @arg LED1
  * @retval None
  */
void LedToggle(Led_TypeDef Led)
{
	LED_PORT[Led]->ODR ^= LED_PIN[Led];
}

